from django.shortcuts import render, redirect
from django.http import HttpResponse, HttpResponseRedirect

# Create your views here.
from django.urls import reverse


def index(request):
    return HttpResponse("你好")


def get_one2one(request):
    a = request.GET['a']
    b = request.GET.get('b')
    content = {'qa': a, 'qb': b}
    return render(request, "viewapp/get_one2one.html", content)


def get_one2one(request):
    all = request.GET.getlist('a')
    content = {'qa': all}
    return render(request, "viewapp/get_one2may.html", content)


def go_user(request):
    return render(request, "viewapp/userinfo.html", {})


def add_userinfo(request):
    uname = request.POST['name']
    uage = request.POST.get('age')
    usex = request.POST['sex']
    uhobby = request.POST.getlist('hobby')
    content = {"uname": uname, "uage": uage, "usex": usex, "uhobby": uhobby}
    return render(request, "viewapp/adduser.html", content)


def add_cookie(request):
    response = HttpResponse()

    if 'h1' in request.COOKIES:
        response.write("<h1>%s</h1>" % request.COOKIES['h1'])

    response.set_cookie('h1', 'hi!', max_age=60)
    return response


def show(request):
    return redirect(reverse('va:js', args=[1]))


def redirect_to(request, id):
    return HttpResponse(id)
